package ru.pachkun.home.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import ru.yandex.qatools.htmlelements.element.Button;
import ru.yandex.qatools.htmlelements.element.TextInput;

public class MainPageFrame extends Page {

	public MainPageFrame(PageManager pages) {
		super(pages);
	}

	@Override
	public MainPageFrame ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.xpath("//a[@href='http://www.caits.ru/addr.php']")));
		return this;
	}
	
	@FindBy(xpath = "//input[@name='login']")
	private TextInput login;
	
	@FindBy(xpath = "//input[@name='password']")
	private TextInput password;
	
	@FindBy(xpath = "//input[@name='submit']")
	private Button submitButton;
	
	@FindBy(css = "a[href*='/servlet/mrpo_operation']")
	private WebElement linkMRPORegistration;
	
	@FindBy(css = "a[href*='/servlet/ems_operation']")
	private WebElement linkEMSRegistration;

	public MainPageFrame setLogin(String text) {
		login.sendKeys(text);
		return this;
	}
	
	public MainPageFrame setPassword(String text) {
		password.sendKeys(text);
		return this;
	}
	
	public MainPageFrame clickSubmitButton() {
		submitButton.click();
		return this;
	}
	
	public EMSRegistrationPage clickLinkEMSRegistration() {
		linkEMSRegistration.click();
		return pages.emsRegistrationPage;
	}
	
	public MRPORegistrationPage clickLinkMRPORegistration() {
		linkMRPORegistration.click();
		return pages.mrpoRegistrationPage;
	}
}
